﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class per_given_record : MpageBase
{
    protected Model.UsersAccount user_account = null;
    protected Model.CMember CMember = null;
    protected List<Model.LotteryBuyDetail> buyInfo = null;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Bind();
            //bindtable();
            bindSelect();
        }
       
    }
    private void Bind()
    {
        if (loginUserInfo != null && loginUserInfo.Id > 0)
        {
            user_account = BLL.UsersAccount.GetModelByuser_id(loginUserInfo.Id);
            CMember = BLL.CMember.GetModel(loginUserInfo.Id);
            if (user_account == null)
            {
                BLL.Session.Remove(BLL.CMember.LoginUserSessionKey);
                Response.Redirect("/default.aspx");
            }
        }
        else
        {
            Response.Redirect("/default.aspx");
        }
    }
    private void bindtable()
    {
        PagedDataSource pds = new PagedDataSource();
        int totalCount = 0;
        string sql = "secret='赠送'  and  User_id=" + loginUserInfo.Id;
        buyInfo = BLL.LotteryBuyDetail.GetPageListBysql(this.AspNetPager1.CurrentPageIndex - 1, this.AspNetPager1.PageSize, sql, out totalCount);
        if (buyInfo != null && buyInfo.Count > 0)
        {
            AspNetPager1.Visible = true;
            AspNetPager1.RecordCount = totalCount;
            pds.AllowPaging = true;
            pds.PageSize = AspNetPager1.PageSize;
            pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;

        }
        else
        { AspNetPager1.Visible = false; }
    }
    protected void bindSelect()
    {
        PagedDataSource pds = new PagedDataSource();
        string sql = "";
        //时间下拉菜单
        int times = int.Parse(this.timesl.SelectedValue.ToString());
        if (times == 0)
        {
            sql = " datediff(day,[AddTime],getdate())=0 ";
        }
        else if (times == 1)
        {
            sql = " datediff(week,[AddTime],getdate())=0 ";
        }
        else if (times == 2)
        {
            sql = " datediff(month,[AddTime],getdate())=0";
        }
        else if (times == 3)
        {
            sql = " datediff(month,[AddTime],getdate())<=3 ";
        }
        else if (times == 4)
        {
            sql = " datediff(month,[AddTime],getdate())<=6 ";
        }
        //彩票类型
        int type = int.Parse(this.typeslddl.SelectedValue.ToString());
        if (type > 0)
        {
            sql += " and User_id=" + loginUserInfo.Id + " and LotteryType=" + type;
        }
        else
        {
            sql += " and User_id=" + loginUserInfo.Id;
        }
        int totalCount = 0;
        buyInfo = BLL.LotteryBuyDetail.GetPageListBysql(this.AspNetPager1.CurrentPageIndex - 1, this.AspNetPager1.PageSize, sql, out totalCount);
        if (buyInfo != null && buyInfo.Count > 0)
        {
            AspNetPager1.Visible = true;
            AspNetPager1.RecordCount = totalCount;
            pds.AllowPaging = true;
            pds.PageSize = AspNetPager1.PageSize;
            pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;

        }
        else
        {
            AspNetPager1.Visible = false;
        }
    }
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        Bind();
        //bindtable();
        bindSelect();
    }

    protected void timesl_SelectedIndexChanged(object sender, EventArgs e)
    {
        Bind();
        bindSelect();
    }
    protected void timesl_SelectedIndexChanged1(object sender, EventArgs e)
    {
        Bind();
        bindSelect();
    }
    protected void ordersl_SelectedIndexChanged(object sender, EventArgs e)
    {
        Bind();
        bindSelect();
    }
    protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
    {
        Bind();
        bindSelect();
    }
    protected void CheckBox2_CheckedChanged(object sender, EventArgs e)
    {
        Bind();
        bindSelect();
    }
}